package com.turing.merchant.controller;

import com.alibaba.fastjson.JSONObject;
import com.turing.merchant.service.MerchantCustomerService;
import com.turing.merchant.service.MerchantService;
import org.springframework.web.bind.annotation.*;
import result.Result;

import javax.annotation.Resource;

@RestController
public class MerchantController {

    @Resource
    private MerchantService merchantService;
    @Resource
    private MerchantCustomerService merchantCustomerService;

    @GetMapping("mer/merList")
    public Result merList(
            @RequestParam(value = "merchantName", required = false) String merchantName,
            @RequestParam(value = "loginAccount", required = false) String loginAccount,
            @RequestParam(value = "merchantPhone",required = false) String merchantPhone,
            @RequestParam(value = "categoryId",required = false) String categoryId,
            @RequestParam(value = "cdType",required = false) Integer cdType,
            @RequestParam(value = "longitude",required = false) String longitude,
            @RequestParam(value = "latitude",required = false) String latitude,
            @RequestParam(value = "cityId",required = false) String cityId,
            @RequestParam(value = "sortType",required = false,defaultValue = "0") Integer sortType,
            @RequestParam(value = "orderType",required = false,defaultValue = "0") Integer orderType,
            @RequestParam(value = "pageNum",required = false) Integer pageNum,
            @RequestParam(value = "pageSize",required = false) Integer pageSize
    ){
        return merchantService.merList(merchantName,loginAccount,merchantPhone,categoryId,cdType,longitude,latitude,cityId,sortType,orderType,pageNum,pageSize);
    }

    @GetMapping("mer/getMerById")
    public Result getMerById(

            @RequestParam(value = "id") String id
    ){
        return merchantService.getMerById(id);
    }

    @PatchMapping("mer/merEdit")
    public Result merEdit(@RequestBody JSONObject jsonObject){
        return merchantService.merEdit(jsonObject);
    }

    @GetMapping("admin/adminList")
    public Result adminList(
            @RequestParam(value = "merchantId") String merchantId,
            @RequestParam(value = "cusNickname",required = false) String cusNickname,
            @RequestParam(value = "cusInfo",required = false) String cusInfo,
            @RequestParam(value = "sortType",defaultValue = "0") Integer sortType,
            @RequestParam(value = "orderType",defaultValue = "0") Integer orderType,
            @RequestParam(value = "pageNum",required = false) Integer pageNum,
            @RequestParam(value = "pageSize",required = false) Integer pageSize
    ){
        return merchantService.adminList(merchantId,cusNickname,cusInfo,sortType,orderType,pageNum,pageSize);
    }
}
